CHILD_PROP_NAME,
CHILD_PROP_TITLE,
CHILD_PROP_ICON_NAME,
- CHILD_PROP_POSITION
+ CHILD_PROP_POSITION,
+ CHILD_PROP_NEEDS_ATTENTION
};
typedef struct _GtkStackChildInfo GtkStackChildInfo;
gchar *name;
gchar *title;
gchar *icon_name;
+ gboolean needs_attention;
};
typedef struct {
P_("The index of the child in the parent"),
-1, G_MAXINT, 0,
GTK_PARAM_READWRITE));
+
+ /**
+ * GtkStack:needs-attention:
+ *
+ * Sets a flag specifying whether the child requires the user attention.
+ * This is used by the #GtkStackSwitcher to change the appearance of the
+ * corresponding button when a page needs attention and it is not the
+ * current one.
+ *
+ * Since: 3.12
+ */
+ gtk_container_class_install_child_property (container_class, CHILD_PROP_NEEDS_ATTENTION,
+ g_param_spec_boolean ("needs-attention",
+ P_("Needs Attention"),
+ P_("Whether this page needs attention"),
+ FALSE,
+ GTK_PARAM_READWRITE));
}
/**
g_value_set_int (value, i);
break;
+ case CHILD_PROP_NEEDS_ATTENTION:
+ g_value_set_boolean (value, info->needs_attention);
+ break;
+
default:
GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
break;
reorder_child (stack, child, g_value_get_int (value));
break;
+ case CHILD_PROP_NEEDS_ATTENTION:
+ info->needs_attention = g_value_get_boolean (value);
+ gtk_container_child_notify (container, child, "needs-attention");
+ break;
+
default:
GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
break;
child_info->name = NULL;
child_info->title = NULL;
child_info->icon_name = NULL;
+ child_info->needs_attention = FALSE;
priv->children = g_list_append (priv->children, child_info);
priv->buttons = g_hash_table_new (g_direct_hash, g_direct_equal);
context = gtk_widget_get_style_context (GTK_WIDGET (switcher));
+ gtk_style_context_add_class (context, "stack-switcher");
gtk_style_context_add_class (context, GTK_STYLE_CLASS_LINKED);
gtk_orientable_set_orientation (GTK_ORIENTABLE (switcher), GTK_ORIENTATION_HORIZONTAL);
}
}
+static void
+update_needs_attention (GtkWidget *widget, GtkWidget *button, gpointer *data)
+{
+ GtkContainer *container;
+ gboolean needs_attention;
+ GtkStyleContext *context;
+
+ container = GTK_CONTAINER (data);
+ gtk_container_child_get (container, widget,
+ "needs-attention", &needs_attention,
+ NULL);
+
+ context = gtk_widget_get_style_context (button);
+ if (needs_attention && !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_NEEDS_ATTENTION);
+ else
+ gtk_style_context_remove_class (context, GTK_STYLE_CLASS_NEEDS_ATTENTION);
+}
+
static void
update_button (GtkStackSwitcher *self,
GtkWidget *widget,
g_free (title);
g_free (icon_name);
+
+ update_needs_attention (widget, button, priv->stack);
}
static void
gtk_box_reorder_child (GTK_BOX (self), button, position);
}
+static void
+on_needs_attention_updated (GtkWidget *widget,
+ GParamSpec *pspec,
+ GtkStackSwitcher *self)
+{
+ GtkWidget *button;
+ GtkStackSwitcherPrivate *priv;
+
+ priv = gtk_stack_switcher_get_instance_private (self);
+
+ button = g_hash_table_lookup (priv->buttons, widget);
+ update_button (self, widget, button);
+}
+
static void
add_child (GtkStackSwitcher *self,
GtkWidget *widget)
g_signal_connect (widget, "child-notify::title", G_CALLBACK (on_title_icon_updated), self);
g_signal_connect (widget, "child-notify::icon-name", G_CALLBACK (on_title_icon_updated), self);
g_signal_connect (widget, "child-notify::position", G_CALLBACK (on_position_updated), self);
+ g_signal_connect (widget, "child-notify::needs-attention", G_CALLBACK (on_needs_attention_updated), self);
g_hash_table_insert (priv->buttons, widget, button);
}
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
priv->in_child_changed = FALSE;
}
+
+ g_hash_table_foreach (priv->buttons,
+ (GHFunc)update_needs_attention,
+ priv->stack);
}
static void